using NHibernate;
using NhibernateDemoCore;

namespace NhibernateDemoConsole
{
    public class BulkLoadCustomers
    {
        public void Execute(ISessionFactory factory)
        {
            using (var session = factory.OpenSession())
            {
                using (var tx = session.BeginTransaction())
                {
                    try
                    {
                        for (var i = 1; i < 501; i++)
                        {
                            var customer = new Customer
                                               {
                                                   Name = string.Format("Customer {0:0000}", i),
                                                   BillingAddress = new Address
                                                                        {
                                                                            Line1 = "450 S State Rd",
                                                                            City = "Marysville",
                                                                            State = "PA",
                                                                            Zip = "17053"
                                                                        }
                                               };

                            session.Save(customer);
                        }
                        tx.Commit();
                    }
                    catch
                    {
                        tx.Rollback();
                        throw;
                    }
                }
            }
        }
    }
}